package com.hspjava.Arrays_;

import java.util.Arrays;
import java.util.Comparator;

public class ArraySortCustom {
    public static void main(String[] args) {
        int[] arr = {10 , 30, 40, 33, 44, 22};
        BubbleControl(arr, new Comparator() {
            @Override
            public int compare(Object o1, Object o2) {
                int i1 = (Integer)o1;
                int i2 = (Integer)o2;
                return i2 - i1;
            }
        });



        System.out.println("======排序后======");
        System.out.println(Arrays.toString(arr));



    }

    public static void BubbleControl(int[] arr, Comparator c) {
        for (int i = 0; i < arr.length - 1; i ++) {
            for (int j = 0; j < arr.length - i - 1; j ++) {
                if (c.compare(arr[j], arr[j + 1]) > 0) {
                    int tmp = arr[j];
                    arr[j] = arr[j + 1];
                    arr[j + 1] = tmp;
                }
            }
        }
    }


}
